package huoye.shops.huoye.mine.presenter;


import java.util.List;

import huoye.shops.base.BasePresenter;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.common.model.OssImageData;
import huoye.shops.huoye.mine.networt.MineService;
import huoye.shops.huoye.mine.view.IEditShopMessageView;
import huoye.shops.huoye.operation.model.Descript;
import huoye.shops.huoye.operation.model.ShopCouponsList;
import huoye.shops.huoye.operation.networt.OperationService;
import huoye.shops.huoye.operation.view.ILimitDiscountView;
import huoye.shops.huoye.user.model.User;


/**
 * Created by uesr on 2017/7/19.
 */

public class EditShopMessagePresenter extends BasePresenter<IEditShopMessageView> {


    private MineService mService;


    //单张图片上传
    public void uploadOssImg(String id, String type, String filePath) {
        //  view.showProcessingIndicator();
        mService.uploadOssImg(id, type, filePath, new MineBaseJsonRequestCallback<OssImageData>(OssImageData.class) {

            @Override
            public void onSuccess(List<OssImageData> list) {
                super.onSuccess(list);
                OssImageData ossImageData = list.get(0);
                 view.setUpload(ossImageData);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });

    }

    //多张图片上传
    public void uploadOssImgMore(String id, String type, List<String> imgUrl) {
        //  view.showProcessingIndicator();
        mService.uploadOssImgMore(id, type, imgUrl, new MineBaseJsonRequestCallback<OssImageData>(OssImageData.class) {

            @Override
            public void onSuccess(List<OssImageData> list) {
                super.onSuccess(list);
                view.setUploadMore(list);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });

    }


    //图片删除
    public void deleteOssImg(String filePath) {
        //  view.showProcessingIndicator();
        mService.deleteOssImg(filePath, new MineBaseJsonRequestCallback<OssImageData>(OssImageData.class) {

            @Override
            public void onSuccess() {
                super.onSuccess();
             //   view.makeToast("OSS图片删除成功！");
                view.setDelImage();
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });

    }


    //商家信息编辑
    public void editShopInfo(String shopName, String contactName, String contactTel, String logoImg, List<String> faceImg, String province, String city,
                             String area, String address, List<Descript> shopDes, List<String> locations) {
        if (shopName.equals("")) {
            view.makeToast("请输入商铺名称");
            return;
        } else if (contactName.equals("")) {
            view.makeToast("请输入联系人");
            return;
        } else if (contactTel.equals("")) {
            view.makeToast("请输入联系电话");
            return;
        }else if (logoImg.equals("")) {
            view.makeToast("请选择商店Logo");
            return;
        } else {
            mService.editShopInfo(shopName,contactName,contactTel,logoImg,faceImg,province,city,area,address,shopDes,locations,
                    new MineBaseJsonRequestCallback<User>(User.class) {
                        @Override
                        public void onSuccess() {
                            super.onSuccess();
                            view.makeToast("商家信息编辑成功");
                            view.finish();
                        }

                        //网络请求失败
                        @Override
                        public void onFailure(String msg, String code, Throwable e) {
                            super.onFailure(msg, code, e);
                            view.makeToast(msg);
                        }

                        //加载结束
                        @Override
                        public void onNetworkFail() {
                            super.onNetworkFail();
                            view.onNetworkFail();
                        }

                        //加载中
                        @Override
                        public void onFinish() {
                            super.onFinish();
                            view.hideProcessingIndicator();
                        }
                    });
        }
    }





    @Override
    public void onStart() {
        mService = new MineService();
    }
}
